﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Device.Location;

namespace ChiantiPhoneListApp.ChiantiServiceReference5 
{

    public partial class Position
    {
        public double ToDecimal()
        {
            double retVal = 0;

            retVal =Math.Abs( Degrees) + (Minutes * 1 / 60) + (Seconds * 1 / 3600);
            if (Degrees < 0)
            {
                return -1 * retVal;
            }
            return retVal;
        }

        public Position(double val)
        {
            double value = Math.Abs(val);
            this.Degrees = (int)value;

            double minutes = (value - this.Degrees) * 60;
            this.Minutes = (int)minutes;

            this.Seconds = (minutes - this.Minutes) * 60;

            if (val < 0)
            {
               Degrees =  Degrees * -1;
            }
        }
    }

    public partial class DealBid : IEquatable<DealBid>
    {
        public bool Equals(DealBid other)
        {
            return (this.ID == other.ID);
        }
    }
    public partial class Deal : IEquatable<Deal>
    {
        private double distanceToDealInMeters = 0;
        
        public double DistanceToDealInMeters
        {
            get { return distanceToDealInMeters; }
            set { distanceToDealInMeters = value; }
        }

        public bool Equals(Deal other)
        {
            return (this.ID == other.ID);
        }

        public bool IsExpired()
        {
            return (DateTime.Now > ExpiryDate);
        }

      
    }

    public partial class Business : IEquatable<Business>
    {
        public bool Equals(Business other)
        {
            return (this.ID == other.ID);
        }

        public string CityStateZip
        {
            get
            {
                return City + "," + State + "," + ZipCode;
            }
        }
    }

    public class DealSummary : INotifyPropertyChanged 
    {
        private string title;
        private long dealID;
        private GeoCoordinate location;

        public GeoCoordinate Location
        {
            get { return location; }
            set { location = value; }
        }

        public long DealID
        {
            get { return dealID; }
            set { dealID = value; }
        }

        public string Title
        {
            get { return title; }
            set { title = value; }
        }
        private string businessName;

        public string BusinessName
        {
            get { return businessName; }
            set { businessName = value; }
        }
        private DateTime expiryDate;

        public DateTime ExpiryDate
        {
            get { return expiryDate; }
            set { expiryDate = value; }
        }

        private string expiresIn;

        public string ExpiresIn
        {
            get { return expiresIn; }
            set { 
                expiresIn = value;
                NotifyPropertyChanged("ExpiresIn");
            
            }
        }

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }




        public DealSummary() { }
        public DealSummary(Deal deal, Business business)
        {
            this.DealID = deal.ID;
            this.title = deal.Title;
            this.businessName = business.Name;
            this.expiryDate = deal.ExpiryDate;
            this.expiresIn = Utilities.CreateExpiresInString(expiryDate - DateTime.Now);
            this.Location = new GeoCoordinate(business.Latitude, business.Longitude);
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }

    
}
